package io.renren.modules.generator.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.generator.entity.DeviceAllEntity;
import io.renren.modules.generator.service.DeviceAllService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;



/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-09-06 10:26:46
 */
@Slf4j
@RestController
@RequestMapping("generator/deviceall")
@Api("接口")
public class DeviceAllController {
    @Autowired
    private DeviceAllService deviceAllService;


    @RequestMapping("/actualquota")
    @ApiOperation("获取实时数据")
    public R actualquota(
            @RequestParam("deviceCodes") String[] deviceCodes
    ){
        return R.ok().put("data", deviceAllService.actualquota(deviceCodes));
    }


    /**
     * 列表
     */
    @RequestMapping("/list")
    @ApiOperation("分页列表")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = deviceAllService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{deviceCodeTime}")
    @ApiOperation("根据id获取实体")
    public R info(@PathVariable("deviceCodeTime") String deviceCodeTime){
		DeviceAllEntity deviceAll = deviceAllService.getById(deviceCodeTime);
        return R.ok().put("deviceAll", deviceAll);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @ApiOperation("保存")
    public R save(@RequestBody DeviceAllEntity deviceAll){
		deviceAllService.save(deviceAll);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @ApiOperation("更新")
    public R update(@RequestBody DeviceAllEntity deviceAll){
		deviceAllService.updateById(deviceAll);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @ApiOperation("删除")
    public R delete(@RequestBody String[] deviceCodeTimes){
		deviceAllService.removeByIds(Arrays.asList(deviceCodeTimes));
        return R.ok();
    }

}
